
#include <csl.h>
#include <csl_cache.h>
#include <csl_dat.h>
#include <chan.h>
#include <scom.h>
#include <utl.h>
#include "appMain.h"
#include "appThreads.h"
#include "appBiosObjects.h"

extern int intHeap,extHeap;


void dm642_init()
{
    // Turn on the cache first

    // Init the EVM
    EVMDM642_init();
}

/* perform all initializations */
void main()
{
    CSL_init();
    CACHE_clean(CACHE_L2ALL, 0, 0);
    CACHE_setL2Mode(CACHE_128KCACHE);
    CACHE_enableCaching(CACHE_EMIFA_CE00);
    CACHE_enableCaching(CACHE_EMIFA_CE01);
    DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);

    /* Initialize ACPY, DMAN */
    ACPY2_6X1X_init();
    DMAN_init();
    DMAN_setup(intHeap);

    /* initialize RF5 modules */
    CHAN_init();
    ICC_init();
    SCOM_init();

    /* setup chan module Ratna - Modified */
    CHAN_setup( intHeap, extHeap, intHeap, SCRBUCKETS, NULL, NULL);

    // name LOG objects to be used for error/warning/general/debug messages.
    UTL_setLogs( &trace, &trace, &trace, &trace );

    tskVideoInputInit();
    tskVideoOutputInit();

    EVMDM642_rset(0x10, 0x20);
    EVMDM642_rset(0x10, 0x08);
    while(! (EVMDM642_rget(0x13) & 0x40));

    tskVideoInputStart();
    tskVideoOutputStart();
    UTL_logDebug( "Video I/O started" );

    tskProcessInit();
    tskProcessStart();
    UTL_logDebug( "Process thread started" );

    thrControlInit();
    thrControlStartup();
    UTL_logDebug( "Control thread started" );

    /* create all SCOM and message objects */
    SCOM_create("INTOPROC", NULL);
    SCOM_create("PROCTOIN", NULL);
    SCOM_create("PROCTOOUT", NULL);
    SCOM_create("OUTTOPROC", NULL);

    UTL_logDebug( "Application started" );

    // show heap usage, now that all threads are initialized and started

    UTL_showHeapUsage( intHeap );
    UTL_showHeapUsage( extHeap );
}
